$(".returnBtn").click(function(){
    window.location.href='/Home/Index/doLast?username='+$("#usr").val()+'&url=/Home/Index/registerExpertise'
});

//选择配音时间段
$("#addtime").click(function(){$("#time").show();});
$("#deltime").click(function(){$("#time").hide();});

addtime(1);

function addtime(list) {
    var timehtml1 = '<select class="timebody1 selectcss" name="voiceTime[]"></select>';
    var timehtml2 = '<select class="timebody2 selectcss" name="voiceTime[]"></select>';
    var timehtml3 = '<select class="timebody3 selectcss" name="voiceTime[]"></select>';
    var timehtml4 = '<select class="timebody4 selectcss" name="voiceTime[]"></select>';
    var timehtml = '<div class="'+'time'+list+' timelength">'+timehtml1+timehtml2+' - '+timehtml3+timehtml4+'<span style="color:#6ba0e7;font-size:14px;cursor: pointer;" onclick="delTime(this)" class="'+'time'+list+'">删除</span></div>';
    $("#time").append(timehtml);
    for (i = 1;i < 25;i++){
        $(".timebody1").append('<option value ="'+i+'">'+i+'时</option>');
        $(".timebody3").append('<option value ="'+i+'">'+i+'时</option>');
    }
    for (i = 0;i < 61;i++){
        $(".timebody2").append('<option value ="'+i+'">'+i+'分</option>');
        $(".timebody4").append('<option value ="'+i+'">'+i+'分</option>');
    }
}
//新增div
$(".addbtn").click(function(){
    if($(".timelength").length > 2){
        layer.msg('最多添加三个时间段');return;
    }
    if ($(".time1").length > 0){
        if ($(".time2").length > 0){
            addtime(3);
        }else{
            addtime(2);
        }
    }else{
        addtime(1);
    }

});

//删除div
function delTime(obj){var cl = obj.className;$("."+cl).remove();}

$(".postBtn").click(function(){
    var list= $('input:radio[name="timeType"]:checked').val();
    if(list == null){
        layer.tips('必须选择一个配音时间', '.ro');return;
    }
    if ($(".time1").length > 0 && list != 0){
        if(parseInt($(".time1 .timebody3").val() * 60) + parseInt($(".time1 .timebody4").val()) <= parseInt($(".time1 .timebody1").val() * 60) + parseInt($(".time1 .timebody2").val())){
            layer.tips('请认真选择配音时间段', '.time1');return;
        }
    }
    if ($(".time2").length > 0 && list != 0){
        if(parseInt($(".time2 .timebody3").val() * 60) + parseInt($(".time2 .timebody4").val()) <= parseInt($(".time2 .timebody1").val() * 60) + parseInt($(".time2 .timebody2").val())){
            layer.tips('请认真选择配音时间段', '.time2');return;
        }
    }
    if ($(".time3").length > 0 && list != 0){
        if(parseInt($(".time3 .timebody3").val() * 60) + parseInt($(".time3 .timebody4").val()) <= parseInt($(".time3 .timebody1").val() * 60) + parseInt($(".time3 .timebody2").val())){
            layer.tips('请认真选择配音时间段', '.time3');return;
        }
    }
    var nickname = $(".nickname").val();
    var password = $(".password").val();
    var repassword = $(".repassword").val();
    var znickname = /^[\u4e00-\u9fa5A-Za-z0-9-_]*$/;
    var zpwd = /[0-9a-zA-Z_]{6,20}/;
    if(nickname == ''){
        layer.tips('昵称不能为空', '.nickname');return;
    }
    if(!znickname.test(nickname) || nickname.length >10) {
        layer.tips('昵称格式不正确或超出长度', '.nickname');return;
    }
    if(password == ''){
        layer.tips('密码不能为空', '.password');return;
    }
    if(!zpwd.test(password)) {
        layer.tips('密码应为英文、数字、下划线6-20位字符', '.password');return;
    }
    if(repassword == ''){
        layer.tips('确认密码不能为空', '.repassword');return;
    }

    if(password != repassword){
        layer.tips('确认密码必须和密码一致', '.repassword');return;
    }
    $("#formid").submit();
    layer.msg('加载中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false, area: '200px',time:100000});
});